Skip to content

feat(enterprise): add optional enterprise integration contracts - #63

Merged
ALikesToCode merged 1 commit into
integrate/gateway-waves-1-5from
feat/enterprise-contracts
Oct 9, 2026
Merged

ALikesToCode merged 1 commit into
integrate/gateway-waves-1-5from
feat/enterprise-contracts

Conversation

@ALikesToCode

Copy link
Copy Markdown
Owner

Summary

Adds optional enterprise integration contracts: typed identity, tenancy, quota and credit boundaries that later organisation, SSO, provisioning and payment modules can build on. This PR adds no enterprise feature. Existing single-principal authentication, key controls and budgets stay authoritative, and registering the contracts activates nothing.

  • Contracts (Python dataclasses and protocols in services/enterprise_contract.py, matching frozen classes in worker/enterprise-contract.mjs):
    • TenantContext {principal_id, org_id?, team_id?, grants_revision}, where a team requires an organisation;
    • IdentityAssertion;
    • QuotaAuthority and CreditAuthority, each with reserve, commit and reconcile;
    • a payment callback that accepts only an immutable, verified PaymentEvent with an idempotency ID.
  • Authority rules:
    • Every call carries opaque scoped IDs, an atomic revision and an operation ID.
    • A result must keep the exact context, scoped ID and operation ID and return the successor revision. Stale, foreign, untyped or denied results raise AuthorityDenied.
    • A missing authority denies.
    • Failures are never retried or turned into success.
  • Adapters:
    • Adapters are explicit, statically registered functions. There's no plugin loading or routing language.
    • The initial legacy adapter represents the existing principal, denies organisation/team scope, and provides no identity, quota, credit or payment authority.
  • Preview:
    • ENTERPRISE_PREVIEW_ENABLED defaults to off; malformed values are off with one warning.
    • When off, GET /admin/enterprise/preview returns 404 before authentication.
    • When on, it is admin-only. It returns a dry-run JSON descriptor (dry_run: true, activation: false, contract names, registered authorities, supported operations) with Cache-Control: no-store, and it calls no authority and mutates nothing.
  • Shared vectors: both test suites read the same contract vectors from the doc, so the two runtimes agree on validation.

Details are in docs/enterprise-contracts.md.

Shared registrations

  • tests/test_enterprise_contracts_worker.mjs in test:worker.
  • worker/enterprise-contract.mjs in the edge module inventory; app.get('/admin/enterprise/preview') in the Flask route inventory.
  • ENTERPRISE_PREVIEW_ENABLED in the Container env keys.
  • app.py gains one call, register_enterprise_preview_routes(app).

No migration, tables, Worker routes or browser-readable headers.

Tests

  • tests/test_enterprise_contracts.py and tests/test_enterprise_contracts_worker.mjs cover:
    • the shared contract vectors;
    • the legacy adapter keeping the single principal and rejecting tenant scope;
    • missing authorities denying;
    • fake authorities preserving scope, revision and operation IDs;
    • stale, foreign and denied results being rejected;
    • identity and payment accepting only explicit verified inputs;
    • fake credit atomic revisions and idempotency;
    • adapter failures that aren't retried or converted to success;
    • flag defaults and the warning without its value;
    • the registered preview returning 404 before authentication when off, and requiring admin with zero mutation when on;
    • existing response bytes and headers being unchanged after registration.
  • Full Python suite: 4,504 passed, 2 skipped, 1 failed. The failure is tests/test_usage_ledger.py::test_prune_removes_old_raw_rows_and_rollups, which waits at most 5 seconds for a background flush. It failed once under heavy machine load, passed in the two earlier full runs, and passes 3 of 3 times on its own; this PR doesn't touch the usage ledger. ruff, mypy and bandit are clean.
  • npm run test:worker: 1,672 passed. npm run test:integration: 7 passed.
  • migrations:check (28 contiguous, additive migrations), test:deploy, free routes, client headers and the wrangler deploy --dry-run bundle all pass.
  • tests/test_frontend_build.mjs fails locally because @tailwindcss/cli is not installed. It fails the same way on main.

Test fixture fix

The first full run failed test_registered_preview_auth_and_zero_mutation (302 instead of 403). tests/test_shadow_eval_routes.py drops app, route_helpers and routes.core from sys.modules and re-imports them, but the cached preview route module keeps its original login and admin checks. The fixture now patches AuthService in the globals of the exact checks the route calls. The ordering that reproduced the failure now passes.

CI notes

  • GitHub python/node jobs: the dependency-audit steps fail on every branch, including main. fix(deps): clear the CI dependency audit advisories #42 fixes that.
  • Workers Builds: fails on this stack because the Wave 3 base adds the AdmissionCoordinator Durable Object migration, which wrangler versions upload cannot apply. This is expected until wrangler deploy runs on main.

This is part of Wave 6. It is based on integrate/gateway-waves-1-5, the Wave 5 integration branch (#60). The README line comes with the Wave 6 integration PR.

Defines frozen identity, tenancy, quota and credit authority contracts with explicit adapters and deny-by-default missing authority, plus an administrator-only dry-run preview at /admin/enterprise/preview. ENTERPRISE_PREVIEW_ENABLED defaults to off, and registering the contracts activates nothing.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 10b27283-9353-46a1-95b5-dd7674bc72aa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
multillm-proxy 13231aa Oct 09 2026, 05:19 AM

@ALikesToCode
ALikesToCode merged commit b2f2fd7 into integrate/gateway-waves-1-5 Oct 9, 2026
4 of 7 checks passed
@ALikesToCode
ALikesToCode deleted the feat/enterprise-contracts branch October 26, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant